/*
** MAME to smse2k definitions and wrapper stuff
*/

#ifndef _MAMETYPEDEFS_H
#define _MAMETYPEDEFS_H

// these are defined in windows.h but various crap overrides them


#ifndef _WINDOWS_
#define UINT8 unsigned char
#define UINT16 unsigned short
#define UINT32 unsigned int
#define UINT64 unsigned long
#define INT8  char
#define INT16 short
#define INT32 int
#define INT64 long
 typedef union {
		struct { UINT8 l,h,h2,h3; } b;
		struct { UINT16 l,h; } w;
		struct { INT8 l,h,h2,h3; } sb;
		struct { INT16 l,h; } sw;
		UINT32 d;
		INT32 sd;
} PAIR;

enum {
	FALSE = 0,
	TRUE,
};


#endif

// Attotime to x stuff, actually realtime stuff
#define ATTOTIME_IN_USEC(usec) (double)usec / 1000000.0

// derp
#define CLOCK_MHZ(clk) (int)(clk * 1000000.0)

enum {
	MMU_PROGRAM_SPACE = 0,
	MMU_IO_SPACE,
};


#define offs_t UINT64
#define U64    UINT64

typedef struct {
	const char* tag;

} device_config;

// MAME classes to SMSE2K classes
#define running_machine CHardware
#define address_space CBaseMMU

typedef int(*cpu_irq_callback)(const device_config *,int);

// MMU wrappers
#define memory_read_byte_8be(mmu, address) mmu->Read8(address)
#define memory_read_byte_8le(mmu, address) mmu->Read8(address)
#define memory_write_byte_8be(mmu, address, data) mmu->Write8(address,data)
#define memory_write_byte_8le(mmu, address, data) mmu->Write8(address,data)
#define memory_raw_read_byte(mmu, addr) mmu->Read8(addr)
#define memory_decrypted_read_byte(mmu, addr) mmu->ReadOp8(addr)

// MMU stuff, almost always assigned to the smse2k MMU system
typedef UINT8	(*read8_space_func)  (address_space *space, offs_t offset);
typedef void	(*write8_space_func) (address_space *space, offs_t offset, UINT8 data);

// Stuff that does nothing because smse2k differs
#define get_safe_token(x) x
#define state_save_register_device_item(x,y,z)
#define state_save_register_device_item_array
#define debugger_instruction_hook(x,y)

// memory_find_address_space is unused (stuff has to go through cpu->AssignMMU)
#define memory_find_address_space(device, space) NULL

// CPU Interface
#define CPU_RESET_NAME(name)			cpu_reset_##name
#define CPU_RESET(name)					void CPU_RESET_NAME(name)(const device_config *device)
#define CPU_RESET_CALL(name)			CPU_RESET_NAME(name)(device)

#define CPU_EXIT_NAME(name)				cpu_exit_##name
#define CPU_EXIT(name)					void CPU_EXIT_NAME(name)(const device_config *device)
#define CPU_EXIT_CALL(name)				CPU_EXIT_NAME(name)(device)

#define CPU_EXECUTE_NAME(name)			cpu_execute_##name
#define CPU_EXECUTE(name)				int CPU_EXECUTE_NAME(name)(const device_config *device, int cycles)
#define CPU_EXECUTE_CALL(name)			CPU_EXECUTE_NAME(name)(device, cycles)

#define CPU_INIT_NAME(name)				cpu_init_##name
#define CPU_INIT(name)					void CPU_INIT_NAME(name)(const device_config *device, cpu_irq_callback irqcallback)
#define CPU_INIT_CALL(name)				CPU_INIT_NAME(name)(device, irqcallback)




// CPU stuff
enum {
	CLEAR_LINE=0,
	PULSE_LINE,
	ASSERT_LINE,
	HOLD_LINE,
};

enum {
	INPUT_LINE_NMI = 32,
};

// Removed from MAME since the big CPU update, all this did was change the base address of where the CPU had to read
#define change_pc(X)

#define INLINE __forceinline

#define M_PI 3.14

// wat
#define ATTR_UNUSED

// devices are unsupported here
//#define device_config void
#define logerror Msg
#define fatalerror Msg
// Including this causes the compiler to shit
//#include "mame/cpuintrf.h"

#endif